package com.team.weigou.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.team.weigou.R;
import com.team.weigou.adapter.TabVpiAdapter;
import com.team.weigou.fragment.JiageFragment;
import com.team.weigou.fragment.RexiaoFragment;
import com.team.weigou.fragment.XinpinFragment;
import com.viewpagerindicator.TabPageIndicator;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Wangs on 2015/7/9.
 */
@ContentView(R.layout.activity_hotinfo_layout)
public class HotInfoActivity extends ActionBarActivity {
    private TabPageIndicator tabPageIndicator;
    private ViewPager viewPager;
    @ViewInject(R.id.hot_info_name)
    private TextView textView;
    private TabVpiAdapter adapter;
    private String keywords;
    private String[] titles = {"价格", "新品", " 热销"};

    private List<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewUtils.inject(this);
        getSupportActionBar().hide();

        Intent intent = this.getIntent();
        String name = intent.getStringExtra("name");
        try {
            keywords = URLEncoder.encode(name, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        textView.setText(name);

        initView();
    }

    private void initView() {
        Bundle data = new Bundle();
        data.putString("keywords", keywords);

        JiageFragment jiageFragment = new JiageFragment();
        jiageFragment.setArguments(data);
        fragmentList.add(jiageFragment);

        XinpinFragment xinpinFragment = new XinpinFragment();
        xinpinFragment.setArguments(data);
        fragmentList.add(xinpinFragment);

        RexiaoFragment rexiaoFragment = new RexiaoFragment();
        rexiaoFragment.setArguments(data);
        fragmentList.add(rexiaoFragment);

        adapter = new TabVpiAdapter(fragmentList,getSupportFragmentManager(),titles);
        viewPager = (ViewPager) this.findViewById(R.id.main_viewpager);
        viewPager.setAdapter(adapter);

        tabPageIndicator = (TabPageIndicator) this.findViewById(R.id.main_vpi_tbi);
        tabPageIndicator.setViewPager(viewPager);
    }

    public void back(View v){
        this.finish();
    }

}
